package com.whsxt.buss.controller;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.whsxt.buss.data.InportData;
import com.whsxt.buss.data.OutportData;
import com.whsxt.buss.domain.BusGoods;
import com.whsxt.buss.domain.BusInport;
import com.whsxt.buss.domain.BusOutport;
import com.whsxt.buss.domain.BusProvider;
import com.whsxt.buss.service.IBusGoodsService;
import com.whsxt.buss.service.IBusOutportService;
import com.whsxt.buss.service.IBusProviderService;
import com.whsxt.common.PageInfo;
import com.whsxt.common.Result;

import cn.hutool.core.util.StrUtil;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 贺炯
 * @since 2019-09-28
 */
@RestController
@RequestMapping("/buss/outport")
public class BusOutportController {
	
	@Autowired
	private IBusOutportService IBusOutportService;
	
	@Autowired
	private IBusGoodsService iBusGoodsService;
	
	@Autowired
	private IBusProviderService iBusProviderService;
	
	@RequestMapping("/list")
	public Object list(OutportData data) {
		IPage<BusOutport> page = new Page<BusOutport>(data.getPage(), data.getLimit());
		QueryWrapper<BusOutport> queryWrapper = new QueryWrapper<BusOutport>();
		queryWrapper.eq(data.getProviderid()!=null&&data.getProviderid()!= ' ', "providerid", data.getProviderid());
		queryWrapper.eq(data.getGoodsid()!=null&&data.getGoodsid()!= ' ', "goodsid", data.getGoodsid());
		queryWrapper.gt(StrUtil.isNotBlank(data.getStartTime()), "outputtime", data.getStartTime());
		queryWrapper.lt(StrUtil.isNotBlank(data.getEndTime()), "outputtime", data.getEndTime());
		IBusOutportService.page(page,queryWrapper);
		List<BusOutport> records = page.getRecords();
		for (BusOutport busOutport : records) {
			Integer goodsid = busOutport.getGoodsid();
			BusGoods byId = iBusGoodsService.getById(goodsid);
			busOutport.setGoodsname(byId.getGoodsname());
			busOutport.setSize(byId.getSize());
			Integer providerid = busOutport.getProviderid();
			BusProvider byId2 = iBusProviderService.getById(providerid);
			busOutport.setProvidername(byId2.getProvidername());
		}
		PageInfo pageInfo = new PageInfo(page.getTotal(), records);
		return new Result(pageInfo);
	}
}

